<template>跳转中...</template>

<script setup lang="ts">
import { useUserStore } from '@/store/modules/user';
import { useRouter, useRoute, RouteRecordRaw } from 'vue-router';
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const menus = userStore.menus;

const getFirstRouteName = (list: RouteRecordRaw[]) => {
  for (let item of list) {
    if (item.meta?.hideInMenu) {
      continue;
    }
    if (item.children && item.children.length) {
      return getFirstRouteName(item.children);
    } else {
      return item.name;
    }
  }
};

const firstRouteName = getFirstRouteName(menus!);
setTimeout(() => {
  if (route.query.redirect) {
    router.replace(route.query.redirect as string);
  } else {
    console.log(router.getRoutes(), '@@@@@@@');
    router.replace({
      name: firstRouteName || 'home',
    });
  }
});
</script>
